home *** CD-ROM | disk | FTP | other *** search
- /* outportb.c --- p 525 */
- #include <dos.h>
- #include <conio.h>
- #define TIMER_FREQ 1193180L /* Timer freq = 1.19 MHz */
- #define TIMER_COUNT 0x42 /* 8253 timer -- count */
- #define TIMER_MODE 0x43 /* 8253 timer control port */
- #define TIMER_OSC 0xb6 /*To use timer as oscillator */
- #define OUT_8255 0x61 /* 8255 PPI output port adrs */
- #define SPKRON 3 /* Bit 0 = control spkr by timer*/
- /* Bit 1 = speaker on/off */
- main()
- {
- unsigned freq, status, ratio, part_ratio;
- char input[81];
- cprintf("Enter frequency in Hz (between 100 and 15000):");
- cscanf("%hu", &freq);
- /* First read and save status of the 8255 chip */
- status = inportb (OUT_8255);
- /* Put timer in oscillator mode */
- outportb (TIMER_MODE, TIMER_OSC);
- ratio = (unsigned)(TIMER_FREQ/freq);
- part_ratio = ratio & 0xff; /* low byte of ratio */
- outportb(TIMER_COUNT, part_ratio);
- part_ratio = (ratio >> 8) & 0xff; /* high byte */
- outportb(TIMER_COUNT, part_ratio);
- /* Finally turn on speaker */
- outportb (OUT_8255, (status : SPKRON));
- /* Ask user to indicate when to stop the
- * annoying tone... */
- cprintf("\nHit return to exit:");
- cgets(input);
- /* Now turn off speaker */
- status = inportb (OUT_8255); /* get current status */
- /* Turn speaker off */
- outportb (OUT_8255, (status & ~SPKRON));
- }